#ifndef __NETWORK_H__
# define __NETWORK_H__

#include <iostream>
#include <list>
#include <string>
#include "IThread.h"
#include "Utils.h"

#ifdef WIN32
	#include <windows.h>
	#define	TTYPE					WINAPI
	typedef	HANDLE					absThread;
	typedef	LPTHREAD_START_ROUTINE	functionPtr;
	typedef	DWORD					RETVAL;
	typedef	LPVOID					functionParam;
#else
	#include <pthread.h>
	#define TTYPE
	typedef	pthread_t*	absThread;
	typedef void*		(*functionPtr)(void*);
	typedef	void*		RETVAL;
	typedef	void*		functionParam;
#endif

#include "Connection.h"

namespace Network
{
	class Data
	{
	private:
		SOCKET					socket;
		SOCKADDR_IN*			saddr;
		std::list<std::string>* list;
		std::list<Connection*>*	cList;

	public:
		Data(SOCKET socket, SOCKADDR_IN* saddr, std::list<std::string>* list, std::list<Connection*>* cList);
		~Data();
		Data(const Data& nd);

		const SOCKET&			getSocket() const;
		SOCKADDR_IN*			getSAddr() const;
		std::list<std::string>*	getList() const;
		std::list<Connection*>*	getCList() const;
	};

	class Recv : public IThread
	{
	private:
		absThread			_t;
		Data*				_data;
		static RETVAL TTYPE	loop(functionParam arg);

	public:
		Recv();
		~Recv();
		void	start(void* data);
		void	stop();
	};

	class Send : public IThread
	{
	private:
		absThread			_t;
		Data*				_data;
		static RETVAL TTYPE	loop(functionParam arg);

	public:
		Send();
		~Send();
		void	start(void* data);
		void	stop();
	};
};

#endif
